package com.example.onlineanswer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.onlineanswer.model.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户Mapper接口
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * 根据用户名查询用户角色信息
     *
     * @param username 用户名
     * @return 用户角色信息
     */
    @Select("SELECT u.id, u.username, u.password, u.nickname, u.email, u.status, u.last_login_time, r.role_code, r.role_name " +
            "FROM sys_user u " +
            "LEFT JOIN sys_user_role ur ON u.id = ur.user_id " +
            "LEFT JOIN sys_role r ON ur.role_id = r.id " +
            "WHERE u.username = #{username} AND u.is_deleted = 0 AND u.status = 1")
    SysUser getUserRoleByUsername(@Param("username") String username);
} 